#pragma once

#include "BasicEvent.h"

namespace events {

class MiscEvents : public BasicEvent {
public:
	enum MiscEventType {
		MISC_EXIT_PROCESS,
		MISC_DUPLICATE_HANDLE
	};

public:
	inline MiscEvents(void) : BasicEvent(BasicEvent::EVENT_MISC), _miscType(MISC_EXIT_PROCESS) {}

	inline MiscEvents(MiscEventType type) : BasicEvent(BasicEvent::EVENT_MISC), _miscType(type) {}

	virtual ~MiscEvents(void) {}

public:
	// EXIT PROCESS
	inline void setExitProcessCode(UINT code) { _info.ep.exitCode = code; }
	inline UINT getExitProcessCode(void) const { return _info.ep.exitCode; }

	// DUPLICATE HANDLE
	inline void setDuplicateHandles(HANDLE hOrig, HANDLE hCopy) { _info.dh.hOrig = hOrig; _info.dh.hCopy = hCopy; }
	inline HANDLE getOrigHandle(void) const { return _info.dh.hOrig; }
	inline HANDLE getCopyHandle(void) const { return _info.dh.hCopy; }

	// implementing ISerializable
public:
	virtual void saveToStream(std::ostream &os) const;
	virtual void readFromStream(std::istream &is);
	virtual void writeDebugInfo(std::ostream &os) const;

private:
	MiscEventType _miscType;

	// for EXIT_PROCESS
	typedef struct {
		UINT exitCode;
	} infoExitProcess;

	// for DUPLICATE_HANDLE
	typedef struct {
		HANDLE hOrig;
		HANDLE hCopy;
	} infoDupHandle;

	// combined
	typedef union {
		infoExitProcess ep; 
		infoDupHandle dh;
	} infoAll;
	infoAll _info;
};

}  // end namespace

